package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sky.dto.MedicinalPageQueryDTO;
import com.sky.entity.Food;
import com.sky.entity.Medicinal;
import com.sky.mapper.MedicinalMapper;
import com.sky.result.PageResult;
import com.sky.service.MedicinalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MedicinalServiceImpl implements MedicinalService {

    @Autowired
    private MedicinalMapper medicinalMapper;

    @Override
    public List<Medicinal> medicinalList() {
        List<Medicinal> medicinalList = medicinalMapper.medList();
        return medicinalList;
    }

    @Override
    public PageResult pageQuery(MedicinalPageQueryDTO medicinalPageQueryDTO) {
        IPage iPage=new Page(medicinalPageQueryDTO.getPage(),medicinalPageQueryDTO.getPageSize());
        LambdaQueryWrapper<Medicinal> lam=new LambdaQueryWrapper<>();
        medicinalMapper.selectPage(iPage,lam);
        long total=iPage.getTotal();
        List<Medicinal> medicinalList=iPage.getRecords();
        PageResult pageResult=new PageResult(total,medicinalList);
        return pageResult;
    }
}
